package com.wkhyapp.lm.adapter;

import android.text.Html;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.wkhyapp.lm.R;
import com.wkhyapp.lm.http.vo.Goods;
import com.wkhyapp.lm.utils.GetTimeAgo;
import com.wkhyapp.lm.utils.ImageLoadUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2021-10-2.
 */

public class GoodsAdapter extends BaseQuickAdapter<Goods, BaseViewHolder> {

    public GoodsAdapter.callBack mCallBack;
    public GoodsAdapter(int layoutResId, List<Goods> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, final Goods item) {

        ImageView goods_iv = helper.getView(R.id.goods_iv);
        ImageView head = helper.getView(R.id.head_iv);
        ImageLoadUtil.setRoundImage_Normal(mContext,item.getImg(),6,goods_iv);
        ImageLoadUtil.setCirlcleImage_Normals(mContext,item.getHeadImg(),head);
        helper.setText(R.id.name_tv,item.getNickname()+"");
        TextView title= helper.getView(R.id.title_tv);
        title.setText(Html.fromHtml(item.getDesc()));
        RelativeLayout sharRel = helper.getView(R.id.share_rl);
        RelativeLayout shopRl = helper.getView(R.id.shop_rl);
        helper.setText(R.id.imgCount_tv,item.getImgCount()+"");
        helper.setText(R.id.time_tv, GetTimeAgo.getTimeAgo(item.getUpdateTime()));

        sharRel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mCallBack.share(item);
            }
        });

        goods_iv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mCallBack.showImg(item);
            }
        });

        title.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mCallBack.info(item);
            }
        });

        shopRl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mCallBack.shop(item);
            }
        });
    }


    public void  setCallBack(GoodsAdapter.callBack callBack){
        this.mCallBack = callBack;
    }


    public interface  callBack{
        void share(Goods item);
        void showImg(Goods item);
        void info(Goods item);
        void shop(Goods item);
    }


}
